﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;

namespace VSTweaker.UI.ViewModels
{
    public class MainWindowViewModel : INotifyPropertyChanged
    {
        public MainWindowViewModel(Grid tabControl)
        {
            AvailableVisualStudioVersions = VisualStudioVersion.GetInstalledVersions();

            _tabControl = tabControl;

            ResetTabs();
        }

        private Grid _tabControl;
        private VisualStudioVersion _selectedVersion;

        public VisualStudioVersion SelectedVisualStudioVersion
        {
            get
            {
                return _selectedVersion;
            }
            set
            {
                _selectedVersion = value;
                OnPropertyChaned("SelectedVisualStudioVersion");
                ResetTabs();
            }
        }

        public IEnumerable<VisualStudioVersion> AvailableVisualStudioVersions { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChaned(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void ResetTabs()
        {
            _tabControl.Children.Clear();

            var view = new Views.Components();
            view.DataContext = new ComponentsViewModel(SelectedVisualStudioVersion);

            _tabControl.Children.Add(view);
        }
    }
}
